//
//  NSString+Size.m
//  BadBoy
//
//  Created by wen on 2017/3/10.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "NSString+Size.h"

@implementation NSString (Size)

- (CGFloat)widthWithFont:(UIFont *)font{
    if (self == nil || [self isEqualToString:@""] || [self isEqual:[NSNull null]]) {
        return 0;
    }
    NSDictionary *attrs = @{NSFontAttributeName : font};
    CGSize size = [self boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
    return floor(size.width)+1;
}
    
- (CGFloat)heightWithFont:(UIFont *)font width:(CGFloat)width{
    NSDictionary *attrs = @{NSFontAttributeName : font};
    CGSize size = [self boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
    return floor(size.height)+1;
}
    
- (CGFloat)widthWithFont:(UIFont *)font widthSpace:(CGFloat)widthSpace{
    NSDictionary *attrs = @{NSFontAttributeName : font, NSKernAttributeName : @5};
    CGSize size = [self boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
    //    return floor(size.width-widthSpace);
    return floor(size.width);
}

- (BOOL)isNotEmpty{
    if (self == nil || [self isEqualToString:@""] || [self isEqual:[NSNull null]]) {
        return NO;
    }
    return YES;
}
@end
